package com.tools.common;

import android.app.ActivityManager;
import android.content.Context;

public class RuntimeUtil {
	
	//VM大小的默认值，单位是MB
		public static final int VM_DEFAULT_SIZE = 48;
	
	/**
	 * 
	 * @param context
	 * @return Return number is MB
	 */
	public static int getVmSize(Context context) {//TODO  如何设置vmsize  VMRuntime.getRuntime().？？
		int vmSize = 0;
		ActivityManager am = (ActivityManager) context
				.getSystemService(Context.ACTIVITY_SERVICE);
		vmSize = am.getMemoryClass(); // getMemoryClass return MB
		if (vmSize > 0) {
			return vmSize;
		} else {
			Runtime rt = Runtime.getRuntime();
			vmSize = (int) (rt.maxMemory() / 1024 / 1024); // Convert bytes to
															// MB
			if (vmSize > 256) { // If there is no such limit, use 96MB as
								// default limit.
				vmSize = 96;
			}
			if (vmSize <= 0) {
				vmSize = VM_DEFAULT_SIZE; // If get fail，use 48MB as
													// default value.
			}
			return vmSize;
		}
	}
}
